
* Set directories

cd /Users/xiaosongw/Dropbox/Research/InformedSources/ReplicationRemove2


* ---------------------- Figure 3: Restoration speed  -------------------------*

* Load data
use ./Data/is_mel_p_2005_2019, clear

* Sample Period
keep if t>=td(1jan2014) & t<=td(31dec2018)


drop if drop_coles == 1
count if !missing(p)

keep if is_cyc_drop == 0 & drop_coles == 0 & cyc_id_bttm > 0 

duplicates drop t cyc_id_bttm cyc_prd_resto, force
collapse (sum) cyc_prd_resto (first) t, by(cyc_id_bttm)
replace cyc_prd_resto = cyc_prd_resto - 1

sum cyc_prd_resto if cyc_id_bttm <= 29, detail
sum cyc_prd_resto if cyc_id_bttm > 29, detail
sum cyc_prd_resto, detail

gen coles_off = cyc_id_bttm > 29
reg cyc_prd_resto coles_off

set scheme s1mono, permanently

* Dates for xlabels
local x0=td(1jan2014)
local x1=td(1jan2015)
local x2=td(1jan2016)
local x3=td(1jan2017)
local x4=td(1jan2018)
local x5=td(1jan2019)
local xis=td(15apr2016)
local xtext=td(20nov2016)


twoway ///
	(line cyc_prd_resto t, connect(stairstep) lcolor(navy)) ///
	(scatter cyc_prd_resto t, mcolor(navy) msize(tiny) ///
	xlabel(`x0' `" "Jan 1"  "2014" "' `x1' `" "Jan 1"  "2015" "' `x2' `" "Jan 1"  "2016" "' `x3' `" "Jan 1"  "2017" "' ///
	`x4' `" "Jan 1"  "2018" "' `x5' `" "Jan 1"  "2019" "', labsize(*0.7) nogrid) ///
	yscale(range(2 11)) ylabel(2(1)11, grid) ///
    xtitle("Cycle Peak Date") ///
    ytitle("Restoration Speed") ///
    legend(off) ///
	xline(`xis') ///
	text(10.5 `xtext' "Coles Informed Sources" "contract expires", justification(left) size(*0.7)) ///
	plotregion(margin(zero) style(none) fcolor(white)) graphregion(color(white)) bgcolor(white))
	graph export ./Output/fig3_speed.pdf, as(pdf) replace
	


